﻿using ConfExpert.Forms.Base;

using DevTeam;

using System;
namespace ConfExpert.Forms.Depo
{
    public partial class AzTuketim : XForm
    {
        public AzTuketim()
        {
            InitializeComponent();
            this.Text = "Hareket Görmeyen Artikeller";
        }

        private void AzTuketim_Load(object sender, EventArgs e)
        {

            //dateEdit1.EditValue = new DateTime(2014, 2, 1);
            gvCustomer.Init("TopuCikilmamisKumas", spnMonth.EditValue.ToInt(-1));
            gvCustomer.AddDetailGrid(gvArticle, "CustomerId");
            gvArticle.AddDetailGrid(gvRoll, "ProductId");

            gvCustomer2.Init("GetAges2", spnMonth.EditValue.ToInt(-1), spnPercentage.EditValue.ToInt(-1));
            gvCustomer2.AddDetailGrid(gvArticle2, "CustomerId");

            GridManager gm = GridManager.GetManager(gvArticle);
            gm.GridMenu.AddMenu("Bu artikelin hareketleri", HareketleriGoster);
            GridManager gm2 = GridManager.GetManager(gvArticle2);
            gm2.GridMenu.AddMenu("Bu artikelin hareketleri", HareketleriGoster2);

            //gvKumas.FormatAsPercentage("Tuketim");
            gvCustomer.FormatAsNumber(0, "Qty");
            //gvCustomer.MakeColumnInvisible("ProductId");
            gvCustomer.MakeReadOnly();
            gvArticle.MakeReadOnly();
            gvCustomer2.MakeReadOnly();
            gvArticle2.MakeReadOnly();
            gvArticle.MakeColumnInvisible("CustomerId");
            gvArticle2.MakeColumnInvisible("ProductId");
            //gvRoll.MakeColumnInvisible("Scan", "ProductId");
            //gvArticle.FormatAsDate("GelisTarihi");
            gvCustomer.AddSummary("Qty");
            gvArticle.AddSummary("Qty");
            gvCustomer.BestFitColumns();
            gvArticle.BestFitColumns();
            gvCustomer2.AddSummary("Stok");
            gvArticle2.AddSummary("Stok");
            gvRoll.AddSummary();
            gvCustomer2.BestFitColumns();
            gvArticle2.BestFitColumns();

            spnPercentage.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            btnGetir.ItemClick += btnGetir_ItemClick;
            //splitContainerControl1.SizeChanged+=new EventHandler(MySizeChanged);
        }

        void btnGetir_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvCustomer.RefreshDataSource(true, "TopuCikilmamisKumas", spnMonth.EditValue.ToInt(-1));
            gvCustomer2.RefreshDataSource(true, "GetAges2", spnMonth.EditValue.ToInt(-1), spnPercentage.EditValue.ToInt(-1));
            //gvKumas.FormatAsPercentage("Tuketim");
            //gvCustomer.FormatAsNumber(0, "DepoMt", "GirenMt", "CikanMt");
            //gvCustomer.MakeColumnInvisible("CustomerId");
            gvArticle.AddSummary("Stok");
            gvArticle.BestFitColumns();
            gvArticle2.AddSummary("Stok");
            gvArticle2.BestFitColumns();
        }

        void HareketleriGoster(object sender, EventArgs e)
        {
            //if (gvCustomer.SelectedRowsCount == 1)
            //{
            int productId = gvArticle.GetFocusedRowCellValue("ProductId").ToInt(-1);
            if (productId > 0)
                using (DepoStokHareketler rzv = new DepoStokHareketler(productId))
                    rzv.ShowDialog();
            //}
        }

        private void HareketleriGoster2(object sender, EventArgs e)
        {
            int productId = gvArticle2.GetFocusedRowCellValue("ProductId").ToInt(-1);
            if (productId > 0)
                using (DepoStokHareketler rzv = new DepoStokHareketler(productId))
                    rzv.ShowDialog();
        }

        private void tabCtrlPassiveArticle_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            if (tabCtrlPassiveArticle.SelectedTabPageIndex == 0)
                spnPercentage.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            else
                spnPercentage.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
        }
    }
}
